package impl;

import bean.Detail;
import dao.DetailDao;
import util.DBHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @classname:DetailDaoImpl
 * @description:
 * @author: Mr.Z
 * @date: 2021/1/1 23:19
 * @version: 0.1
 * @since:1.8
 */
public class DetailDaoImpl implements DetailDao {

    public DetailDaoImpl(Connection conn) {
        this.conn = conn;
    }
    public DetailDaoImpl() {
    }
    private Connection conn;
    private String sql;
    private PreparedStatement ps;
    private ResultSet rs;
    private int result;
    @Override
    public Detail selectDetailById(int id) {
        conn = DBHelper.getCon();
        sql = "select * from detail where id=?";
        Detail detail = null;
        try {
            ps = conn.prepareStatement(sql);
            ps.setInt(1,id);
            rs =ps.executeQuery();
            while (rs.next()){
                detail = new Detail(rs);
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return detail;
    }
}
